package com.fiberhome.nas.core.database.di

import android.content.Context
import androidx.room.Room
import com.fiberhome.nas.core.database.AppDatabase
import com.fiberhome.nas.core.database.dao.UploadTaskDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

/**
 * 数据库模块
 */
@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {

    /**
     * 提供数据库实例
     */
    @Provides
    @Singleton
    fun provideDatabase(
        @ApplicationContext context: Context
    ): AppDatabase {
        return Room.databaseBuilder(
            context,
            AppDatabase::class.java,
            AppDatabase.DATABASE_NAME
        ).build()
    }

    /**
     * 提供上传任务数据访问对象
     */
    @Provides
    @Singleton
    fun provideUploadTaskDao(database: AppDatabase): UploadTaskDao {
        return database.uploadTaskDao()
    }
}